package com.why.blog.controller;

import com.why.blog.bean.Blog;
import com.why.blog.service.BlogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * @program: blog
 * @description:
 * @author: @why
 * @create: 2021-01-17 21:25
 **/
@Slf4j
@Controller
public class detailController {

    @Autowired
    private BlogService blog;

    @GetMapping("/detail/{blogId}")
    public String detail(@PathVariable("blogId") Integer blogId, Model model) {

        Blog blog = this.blog.getBlogById(blogId);
        this.blog.blogViewsAutoIncrement(blogId);
        model.addAttribute("blogContent", blog);
        // log.error(blog.toString());

        return "detail";
    }
}
